package com.zzhua.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class UserServlet extends HttpServlet {

    @Override
    public void init() throws ServletException {
        System.out.println("userServlet...init初始化");
    }

    private Integer i = 0;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // resp.setContentType("text/html;charset=utf-8"); // 或者如下设置,否则会中文乱码
        HttpSession session = req.getSession(true);
        session.setAttribute(i + "", i++);
        resp.setHeader("content-type","text/plain;charset=UTF-8");
        resp.getWriter().write("Hello, 你好!");
    }
}
